/**
 * // Definition for a Node.
 * function Node(val,children) {
 *    this.val = val;
 *    this.children = children;
 * };
 */

/**
 * @param {Node|null} root
 * @return {number[][]}
 */
 var levelOrder = function(root) {
    let res = []
    let queue = []
    if(!root) return res
    queue.push(root)
    while(queue.length){
      let curLever = []
      let len = queue.length
      for(let i = 0;i < len;i++){
        let node = queue.shift()
        curLever.push(node.val)
        let children = node.children
        children.forEach((child)=>{
          queue.push(child)
        })
      }
      res.push(curLever)
    }
    return res
};